package com.vdf.sisconsolid.rest.definition;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.vdf.sisconsolid.rest.RestBase;
import com.vdf.sisconsolid.rest.type.Color;

@Path("colors")
public class RestColor extends RestBase {
	
	static Map responseColor;
	static int countId = 3;
	static List<Color> clList = new ArrayList<Color>();
	static {
		responseColor = new HashMap();
		
		Color cl = new Color();
		cl.setId(1L);
		cl.setLongName("Long Name1");
		cl.setShortName("Short Name1");
		cl.setCreatedDate(new Date());
		cl.setActive(true);
		clList.add(cl);
		Color cl2 = new Color();
		cl2.setId(2L);
		cl2.setLongName("Long Name2");
		cl2.setShortName("Short Name2");
		cl2.setCreatedDate(new Date());
		cl2.setActive(true);
		clList.add(cl2);
		
	}

	@GET
	@Produces("application/json")
	public Map<String, Object> get() {
		return super.getResponseRest(true,"Data Loaded", clList, clList.size());
	}

	@POST
	@Produces("application/json")
	public Map<String, Object> post(Color color) {
		color.setId((long)countId++);
		clList.add(color);
		return super.getResponseRest(true,"Data Loaded", color);
	}

	@PUT
	@Path("{id}")
	@Produces("application/json")
	public void put(@PathParam("id")long id, Color color) {
		clList.set(clList.indexOf(color), color);

	}

	@DELETE
	@Path("{id}")
	@Produces("application/json")
	public void delete(@PathParam("id") long id) {
		Color cl = new Color();
		cl.setId(id);
		clList.remove(clList.indexOf(cl));
	}

}
